

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>qlab &mdash; quippy 7ea04c5+ documentation</title>
  

  
  
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
        <script type="text/javascript" src="../_static/language_data.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "math|output_area", "processEscapes": true, "ignoreClass": "document", "inlineMath": [["$", "$"], ["\\(", "\\)"]]}})</script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/theme_overrides.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> quippy
          

          
            
            <img src="../_static/hybrid.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                7ea04c5+
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
    
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">Introduction to <code class="docutils literal notranslate"><span class="pre">quippy</span></code></a></li>
<li class="toctree-l1"><a class="reference internal" href="../install.html">Installation of QUIP and quippy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Tutorials/index.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quippy.html">Quippy library reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../visualisation.html">Visualisation Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fortran_wrapper.html">Appendix: wrapping Fortran 90 Code</a></li>
<li class="toctree-l1"><a class="reference internal" href="../teach_sparse.html">Command line options of the teach_sparse main program</a></li>
</ul>

            
          
    <p></p>
    <ul>
        <li><a href="../genindex.html">Index</a></li>
        <li><a href="../py-modindex.html">Module Index</a></li>
        <li><a href="../search.html">Search Page</a></li>
        <li><a href="index.html">Module Source Code</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">quippy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">Module code</a> &raquo;</li>
        
      <li>qlab</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for qlab</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">The :mod:`qlab` module provides a :mod:`pylab &lt;matplotlib.pyplot&gt;`\ -style</span>
<span class="sd">interface to :mod:`quippy` and :mod:`atomeye`, and is designed for interactive use,</span>
<span class="sd">especially in conjunction with `ipython &lt;http://www.ipython.org&gt;`_.</span>

<span class="sd">Viewing Atoms</span>
<span class="sd">-------------</span>

<span class="sd">The most important function defined in this module is :func:`view`, which is</span>
<span class="sd">used to open a new viewer or to update what is displayed in an existing viewer.</span>
<span class="sd">Here&#39;s an example session to give some ideas of how :mod:`qlab` can be used::</span>

<span class="sd">   from qlab import *    # Import all numpy, quippy and atomeye functions</span>

<span class="sd">   d = diamond(5.44, 14) # Make an 8-atom silicon unit cell</span>
<span class="sd">   view(d)               # Pops up an AtomEye window to display our cell</span>
<span class="sd">   capture(&#39;si8.png&#39;)    # Capture a screen shot to file &quot;si8.png&quot;</span>

<span class="sd">.. image:: si8.png</span>
<span class="sd">   :align: center</span>

<span class="sd">Once a viewer window is open, you can run all the methods of the</span>
<span class="sd">:class:`atomeye.AtomEyeViewer` class as top-level functions in the</span>
<span class="sd">which affect the current viewer. This means that you can type, e.g.::</span>

<span class="sd">    aux_property_coloring(&quot;z&quot;)</span>

<span class="sd">to colour the Atoms being displayed in the current viewer by their</span>
<span class="sd">atomic number :attr:`property &lt;~.Atoms.atoms.properties&gt;`, or::</span>

<span class="sd">    change_bgcolor((0, 0, 0))</span>
<span class="sd">    resize(640,480)</span>

<span class="sd">to change the background colour and size of the window. To redraw the</span>
<span class="sd">display, just repeat the :func:`view` command.</span>

<span class="sd">.. _qlab_atom_coloring:</span>

<span class="sd">Custom Atom Colouring</span>
<span class="sd">---------------------</span>

<span class="sd">The :meth:`~atomeye.AtomEyeViewer.aux_property_coloring` method is</span>
<span class="sd">overloaded to allow custom arrays to be visualised, e.g. to highlight</span>
<span class="sd">the atoms where :math:`x \ge a/2`::</span>

<span class="sd">   aux_property_coloring(d.pos[1,:] &gt;= d.lattice[1,1]/2.)</span>

<span class="sd">.. image:: qlab-aux-property-colouring.png</span>
<span class="sd">   :align: center</span>
<span class="sd">   :width: 400</span>

<span class="sd">You can quickly find individual atoms or groups of atoms by passing an</span>
<span class="sd">integer or list of integers to :func:`aux_property_coloring`::</span>

<span class="sd">   aux_property_coloring(1) # highlight first atom (counting from 1 by default)</span>

<span class="sd">Note that these indices respect the global ``fortran_indexing`` setting</span>
<span class="sd">, i.e. they are zero-based if :func:`~quippy.get_fortran_indexing`</span>
<span class="sd">returns True and one-based if it returns False.</span>

<span class="sd">To read off the properties of an individual atom, `right click` on it</span>
<span class="sd">in the AtomEye window. Again, the starting point for the indices</span>
<span class="sd">printed depends on ``fortran_indexing``. The values used for colouring</span>
<span class="sd">the atom are in the ``_show`` property.</span>

<span class="sd">Here is a more advanced example showing how to draw arrows to visualise a vector</span>
<span class="sd">property (the forces on the atoms), and to colour the atoms by a component of the</span>
<span class="sd">stress tensor::</span>

<span class="sd">    d = diamond(5.44, 14)      # Make an 8-atom silicon unit cell</span>
<span class="sd">    s = supercell(d, 5, 5, 5)  # Make a supercell of the Si bulk</span>
<span class="sd">    view(s)                    # Visualise the system</span>
<span class="sd">    s.rattle(0.01)             # Randomise the atomic positions a little</span>
<span class="sd">    </span>
<span class="sd">    p = Potential(&#39;IP SW&#39;)     # Make a Stillinger-Weber potential calculator</span>
<span class="sd">    s.set_calculator(p)        # Associate it with our supercell</span>

<span class="sd">    f = s.get_forces()</span>
<span class="sd">    draw_arrows(f)  # draw vectors on the atoms to represent forces</span>

<span class="sd">    sigma = s.get_stresses()</span>
<span class="sd">    aux_property_coloring(sigma[:, 1, 1])  # colour atoms by sigma_yy</span>

<span class="sd">.. image:: qlab-force-stress.png</span>
<span class="sd">   :align: center</span>
<span class="sd">   :width: 600</span>


<span class="sd">Viewing Trajectories</span>
<span class="sd">--------------------</span>

<span class="sd">You can also pass a list of Atoms objects or a trajectory filename to</span>
<span class="sd">:func:`view` to visualise a sequence of frames. For example, here&#39;s a</span>
<span class="sd">sequence of silicon unit cells with increasing lattice constant::</span>

<span class="sd">   ds = [diamond(5.44+0.005*x, 14) for x in range(100)]</span>
<span class="sd">   view(ds)</span>

<span class="sd">Use `Insert` and `Delete` to move through the frames, or `Ctrl+Insert`</span>
<span class="sd">and `Ctrl+Delete` to jump to the first/last frame. Note the frame</span>
<span class="sd">number is printed in the window title. There are also :func:`first`,</span>
<span class="sd">:func:`last`, :func:`forward`, and :func:`backward` functions.</span>

<span class="sd">There is also a command line script `quippy` which starts an `ipython` shell</span>
<span class="sd">and imports everything from :mod:`qlab` automatically, and opens</span>
<span class="sd">viewers for any file given on the command line, e.g. from the shell ::</span>

<span class="sd">   $ quippy traj.nc</span>

<span class="sd">will fire up `ipython`, load everything from</span>
<span class="sd">:mod:`qlab` and then open a viewer for the file ``traj.nc``.</span>

<span class="sd">When working with large trajectory files, the :func:`clip_visible`</span>
<span class="sd">function is useful to restrict the number of atoms loaded from disk</span>
<span class="sd">and displayed, which can make visualising big systems much more</span>
<span class="sd">managable.</span>

<span class="sd">There is a :func:`gcv` function to get a reference to the current</span>
<span class="sd">viewer (short for&quot;get current viewer&quot;, in analogy with</span>
<span class="sd">:func:`~matplotlib.pyplot.gcf` and :func:`~matplotlib.pyplot.gca`</span>
<span class="sd">in :mod:`pylab &lt;matplotlib.pyplot&gt;`), and a similarily named :func:`gcat`</span>
<span class="sd">(&quot;get current atoms&quot;) to get a reference to the current Atoms being viewed.</span>
<span class="sd">For a trajectory with multiple frames, this corresponds to the current frame.</span>

<span class="sd">You can set the current frame to 10 directly with::</span>

<span class="sd">   set_frame(10)</span>

<span class="sd">Or specify that the frame should advance by 5 steps each time `Insert`</span>
<span class="sd">is pressed with::</span>

<span class="sd">   set_delta(5)</span>

<span class="sd">If you would like to make a movie of your simulation, you can use</span>
<span class="sd">the :func:`render_movie` function::</span>

<span class="sd">   render_movie(&#39;movie.mp4&#39;)</span>

<span class="sd">This function renders each frame to a ``.jpg`` file, before combining the</span>
<span class="sd">snapshots with the `ffmpeg &lt;http://www.ffmpeg.org/&gt;`_ tool (which needs to</span>
<span class="sd">be installed for this to work). There is a `hook` function which is called at</span>
<span class="sd">each frame to allow change to be made to the Atoms object. For example, to run</span>
<span class="sd">a 1 ps MD and render the movie of every 10th frame::</span>

<span class="sd">   d = diamond(5.44, 14)           # Usual 8-atom cell</span>
<span class="sd">   s = supercell(d, 5, 5, 5)       # Make a supercell</span>
<span class="sd">   p = Potential(&#39;IP SW&#39;)          # Make a Stillinger-Weber potential</span>
<span class="sd">   s.set_cutoff(p.cutoff()+1.)     # Neighbour cutoff for atoms is pot cutoff + 1 A</span>

<span class="sd">   ds = DynamicalSystem(s)         # Construct a DynamicalSystem from our Atoms</span>
<span class="sd">   ds.rescale_velo(1000.)          # Set the initial temperature to 1000 K</span>
<span class="sd">   traj = ds.run(p, 1.0, 1000, save_interval=10) # Run 1 ps of dynamics</span>

<span class="sd">   view(traj)                      # Visualise the trajectory: 100 frames long</span>
<span class="sd">   aux_property_coloring(&#39;avg_ke&#39;) # Colour atoms by their time-averaged kinetic energy</span>
<span class="sd">   toggle_aux_property_thresholds_ridid() # Fix the colour scale during movie</span>
<span class="sd">   toggle_aux_property_thresholds_saturation() # Don&#39;t make any atoms invisible</span>
<span class="sd">   render_movie(&#39;traj.mp4&#39;)        # Make the movie</span>

<span class="sd">The movie generated by this script looks like this:</span>

<span class="sd">.. video:: traj 640 320</span>

<span class="sd">.. _qlab_select_atoms:</span>

<span class="sd">Selecting Atoms</span>
<span class="sd">---------------</span>

<span class="sd">The :func:`select_atoms` function is useful for graphically selecting a</span>
<span class="sd">group of atoms, e.g. to manually define an initial QM region for a</span>
<span class="sd">:ref:`QM/MM calculation &lt;qmmm_tutorial&gt;`. After invoking the function, right</span>
<span class="sd">clicking on atoms you want to select. They will be highlighted in red. When you</span>
<span class="sd">are done, press `Enter`. Here&#39;s an example `ipython` session::</span>

<span class="sd">    In [9]: view(s)</span>
<span class="sd">    Reusing viewer named at</span>
<span class="sd">    Out[9]: &lt;AtomsViewer object at 0x10b9f19d0 fpointer=(-33474560, 32762)&gt;</span>
<span class="sd">    In [10]: atoms_list = select_atoms()</span>
<span class="sd">    Right click to select atoms. Press ENTER to finish.</span>
<span class="sd">    indices = [ 224 265 261</span>
<span class="sd">     ]</span>

<span class="sd">If you want to add to the selection, run :func:`select_atoms` again with</span>
<span class="sd">the `reset` argument set to False. To customise the value applied to atoms</span>
<span class="sd">which are clicked on, use the `value` argument: e.g. to de-select atoms</span>
<span class="sd">clicked on by mistake, you could do::</span>

<span class="sd">    select_atoms(reset=False, value=False)</span>

<span class="sd">By default the selection is saved as a logical property named ``selection_mask``.</span>
<span class="sd">This name can be changed with the `markname` argument, e.g. to set the `hybrid`</span>
<span class="sd">property, you could could use::</span>

<span class="sd">    qm_list = select_atoms(markname=&#39;hybrid&#39;, value=HYBRID_ACTIVE_MARK, reset=False)</span>


<span class="sd">Multiple Viewers</span>
<span class="sd">----------------</span>

<span class="sd">By default a single viewer window is reused for individual Atoms</span>
<span class="sd">objects, while a new window is opened for each different trajectory</span>
<span class="sd">filename. You can override this with the `recycle` argument to</span>
<span class="sd">:func:`view`, e.g. to open a second window for a copy of `d`::</span>

<span class="sd">    d2 = d.copy()</span>
<span class="sd">    view(d2, recycle=False)</span>

<span class="sd">You can close a viewer by pressing `q` when it has the mouse focus.</span>
<span class="sd">Each viewer has a :attr:`~QuippyViewer.name` attribute which can be</span>
<span class="sd">use to get a reference to it with the :func:`get_viewer` function.</span>

<span class="sd">For trajectories read from files, the names are derived from the</span>
<span class="sd">filename. The default viewer for :class:`Atoms` objects is named `at`</span>
<span class="sd">and for the default viewers for :class:`AtomsList` and :class:`AtomsReader`</span>
<span class="sd">objects is called `al`. :func:`get_viewer_names` returns a list of the names af</span>
<span class="sd">all the viewers currently open.</span>

<span class="sd">Usually referring to the current viewer with :func:`gcv` is sufficient,</span>
<span class="sd">but you may want to change the default focus for console commands with</span>
<span class="sd">:func:`scv`, e.g. to set the current viewer to the one visualising the</span>
<span class="sd">file ``traj.nc``::</span>

<span class="sd">   scv(get_viewer(&#39;traj&#39;))</span>


<span class="sd">.. note::</span>

<span class="sd">    :mod:`qlab` combines all the :mod:`numpy`, :mod:`quippy` and :mod:`atomeye` functions</span>
<span class="sd">    into a single namespace, so ``from qlab import *`` is roughly equivalent to::</span>

<span class="sd">        import numpy as np</span>
<span class="sd">        from numpy import *</span>
<span class="sd">        import quippy</span>
<span class="sd">        from quippy import *</span>
<span class="sd">        from atomeye import *</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">inspect</span>
<span class="kn">import</span> <span class="nn">itertools</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">numpy</span> <span class="k">import</span> <span class="o">*</span>

<span class="kn">import</span> <span class="nn">quippy</span>
<span class="kn">from</span> <span class="nn">quippy</span> <span class="k">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">atomeye</span> <span class="k">import</span> <span class="o">*</span>

<span class="kn">from</span> <span class="nn">quippy.cinoutput</span> <span class="k">import</span> <span class="n">CInOutputReader</span>

<span class="n">__alldoc__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;QuippyViewer&#39;</span><span class="p">,</span> <span class="s1">&#39;AtomsViewer&#39;</span><span class="p">,</span> <span class="s1">&#39;AtomsListViewer&#39;</span><span class="p">,</span> <span class="s1">&#39;AtomsReaderViewer&#39;</span><span class="p">,</span>
              <span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="s1">&#39;gcv&#39;</span><span class="p">,</span> <span class="s1">&#39;gcat&#39;</span><span class="p">,</span> <span class="s1">&#39;scv&#39;</span><span class="p">,</span> <span class="s1">&#39;get_viewer_names&#39;</span><span class="p">,</span> <span class="s1">&#39;get_viewers&#39;</span><span class="p">,</span>
              <span class="s1">&#39;highlight_qm_region&#39;</span><span class="p">,</span> <span class="s1">&#39;redraw&#39;</span><span class="p">,</span> <span class="s1">&#39;run_command&#39;</span><span class="p">,</span> <span class="s1">&#39;run_script&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span>
              <span class="s1">&#39;setp&#39;</span><span class="p">,</span> <span class="s1">&#39;save_script&#39;</span><span class="p">,</span> <span class="s1">&#39;toggle_coordination_coloring&#39;</span><span class="p">,</span> <span class="s1">&#39;translate&#39;</span><span class="p">,</span>
              <span class="s1">&#39;shift_xtal&#39;</span><span class="p">,</span> <span class="s1">&#39;rotate&#39;</span><span class="p">,</span> <span class="s1">&#39;advance&#39;</span><span class="p">,</span> <span class="s1">&#39;shift_cutting_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;change_bgcolor&#39;</span><span class="p">,</span>
              <span class="s1">&#39;change_atom_r_ratio&#39;</span><span class="p">,</span> <span class="s1">&#39;change_bond_radius&#39;</span><span class="p">,</span> <span class="s1">&#39;change_view_angle_amplification&#39;</span><span class="p">,</span>
              <span class="s1">&#39;toggle_parallel_projection&#39;</span><span class="p">,</span> <span class="s1">&#39;toggle_bond_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;toggle_small_cell_mode&#39;</span><span class="p">,</span>
              <span class="s1">&#39;normal_coloring&#39;</span><span class="p">,</span> <span class="s1">&#39;aux_property_coloring&#39;</span><span class="p">,</span> <span class="s1">&#39;central_symmetry_coloring&#39;</span><span class="p">,</span>
              <span class="s1">&#39;change_aux_property_threshold&#39;</span><span class="p">,</span> <span class="s1">&#39;reset_aux_property_thresholds&#39;</span><span class="p">,</span>
              <span class="s1">&#39;toggle_aux_property_thresholds_saturation&#39;</span><span class="p">,</span> <span class="s1">&#39;toggle_aux_property_thresholds_rigid&#39;</span><span class="p">,</span>
              <span class="s1">&#39;rcut_patch&#39;</span><span class="p">,</span> <span class="s1">&#39;select_gear&#39;</span><span class="p">,</span> <span class="s1">&#39;cutting_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;shift_cutting_plane_to_anchor&#39;</span><span class="p">,</span>
              <span class="s1">&#39;delete_cutting_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;flip_cutting_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;capture&#39;</span><span class="p">,</span> <span class="s1">&#39;change_wireframe_mode&#39;</span><span class="p">,</span>
              <span class="s1">&#39;change_cutting_plane_wireframe_mode&#39;</span><span class="p">,</span> <span class="s1">&#39;get_frame&#39;</span><span class="p">,</span> <span class="s1">&#39;set_frame&#39;</span><span class="p">,</span> <span class="s1">&#39;get_delta&#39;</span><span class="p">,</span>
              <span class="s1">&#39;set_delta&#39;</span><span class="p">,</span> <span class="s1">&#39;first&#39;</span><span class="p">,</span> <span class="s1">&#39;last&#39;</span><span class="p">,</span> <span class="s1">&#39;forward&#39;</span><span class="p">,</span> <span class="s1">&#39;backward&#39;</span><span class="p">,</span> <span class="s1">&#39;load_atom_color&#39;</span><span class="p">,</span>
              <span class="s1">&#39;load_aux&#39;</span><span class="p">,</span> <span class="s1">&#39;look_at_the_anchor&#39;</span><span class="p">,</span> <span class="s1">&#39;observer_goto&#39;</span><span class="p">,</span> <span class="s1">&#39;xtal_origin_goto&#39;</span><span class="p">,</span>
              <span class="s1">&#39;find_atom&#39;</span><span class="p">,</span> <span class="s1">&#39;resize&#39;</span><span class="p">,</span> <span class="s1">&#39;change_aux_colormap&#39;</span><span class="p">,</span> <span class="s1">&#39;draw_arrows&#39;</span><span class="p">,</span>
              <span class="s1">&#39;wait&#39;</span><span class="p">,</span> <span class="s1">&#39;get_visible&#39;</span><span class="p">,</span> <span class="s1">&#39;clip_visible&#39;</span><span class="p">,</span> <span class="s1">&#39;select_atoms&#39;</span><span class="p">,</span> <span class="s1">&#39;render_movie&#39;</span><span class="p">,</span>
              <span class="s1">&#39;set_cutoffs&#39;</span><span class="p">]</span>

<span class="n">_viewers</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">_current_viewer</span> <span class="o">=</span> <span class="kc">None</span>

<div class="viewcode-block" id="QuippyViewer"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer">[docs]</a><span class="k">class</span> <span class="nc">QuippyViewer</span><span class="p">(</span><span class="n">AtomEyeViewer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;quippy-specific extensions to AtomEyeViewer&quot;&quot;&quot;</span>

    <span class="n">_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;verbose&#39;</span><span class="p">,</span> <span class="s1">&#39;echo&#39;</span><span class="p">,</span>
               <span class="s1">&#39;filename&#39;</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">,</span> <span class="s1">&#39;frame&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">,</span>
               <span class="s1">&#39;cache_mem_limit&#39;</span><span class="p">,</span> <span class="s1">&#39;block&#39;</span><span class="p">]</span>
    
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="k">global</span> <span class="n">_viewers</span><span class="p">,</span> <span class="n">_current_viewer</span>

        <span class="n">AtomEyeViewer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_selection_value</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_prev_viewer</span> <span class="o">=</span> <span class="n">_current_viewer</span>
        <span class="n">_current_viewer</span> <span class="o">=</span> <span class="bp">self</span>
        <span class="n">_viewers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">_current_viewer</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_cutoffs</span><span class="p">()</span> <span class="c1"># syncronise QUIP cutoffs with AtomEye</span>
                        
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="nf">_property_hook</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">at</span><span class="p">,</span> <span class="n">auxprop</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">at</span><span class="p">,</span> <span class="s1">&#39;properties&#39;</span><span class="p">):</span>
            <span class="k">return</span>

        <span class="k">if</span> <span class="n">auxprop</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span><span class="nb">str</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span><span class="nb">int</span><span class="p">):</span>
                <span class="n">_show</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">==</span> <span class="n">auxprop</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">indices</span><span class="p">]</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span> <span class="nb">set</span><span class="p">):</span>
                <span class="n">_show</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="ow">in</span> <span class="n">auxprop</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">indices</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">_show</span> <span class="o">=</span> <span class="n">auxprop</span>

            <span class="c1"># allow ASE-style vector arrays</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">_show</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span> <span class="ow">and</span> <span class="n">_show</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">n</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
               <span class="n">_show</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">_show</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">at</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="s1">&#39;_show&#39;</span><span class="p">):</span>
                <span class="k">del</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="s1">&#39;_show&#39;</span><span class="p">]</span>
            <span class="n">at</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="s1">&#39;_show&#39;</span><span class="p">,</span> <span class="n">_show</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">auxprop</span> <span class="o">=</span> <span class="s1">&#39;_show&#39;</span>

        <span class="c1"># Ensure auxprop is one of the first AUX_PROPERTY_COLORING</span>
        <span class="c1"># columns by swapping it with an inessential property if necessary.</span>
        <span class="n">prop_idx</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="n">ncols</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">or</span> <span class="mi">1</span>
            <span class="n">prop_idx</span> <span class="o">+=</span> <span class="n">ncols</span>
            <span class="k">if</span> <span class="n">key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="n">auxprop</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span>
                <span class="k">break</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Unknown Atoms property </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">auxprop</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">prop_idx</span> <span class="o">&gt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">CONFIG_MAX_AUXILIARY</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">swapprop</span> <span class="ow">in</span> <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">swapprop</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;pos&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;species&#39;</span><span class="p">]:</span>
                    <span class="k">break</span>
            <span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">swap</span><span class="p">(</span><span class="n">auxprop</span><span class="p">,</span> <span class="n">swapprop</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">auxprop</span>

    <span class="c1"># def _enter_hook(self, atoms):</span>
    <span class="c1">#     def hook(at):</span>
    <span class="c1">#         if self.is_alive:</span>
    <span class="c1">#             self.redraw()</span>
    <span class="c1">#     atoms.update_redraw_hook = hook</span>
    <span class="c1">#     atoms.add_hook(atoms.update_redraw_hook)</span>

    <span class="c1"># def _exit_hook(self, atoms):</span>
    <span class="c1">#     atoms.remove_hook(atoms.update_redraw_hook)</span>

    <span class="k">def</span> <span class="nf">_close_hook</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">global</span> <span class="n">_viewers</span><span class="p">,</span> <span class="n">_current_viewer</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">_viewers</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">_viewers</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">_current_viewer</span> <span class="ow">is</span> <span class="bp">self</span><span class="p">:</span>
            <span class="n">_current_viewer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_prev_viewer</span>

    <span class="k">def</span> <span class="nf">_click_hook</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atoms</span><span class="p">,</span> <span class="n">idx</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">atoms</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span><span class="p">][</span><span class="n">idx</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_selection_value</span>
            <span class="nb">print</span> <span class="n">idx</span><span class="p">,</span>
            <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
            <span class="nb">print</span>
            <span class="n">atoms</span><span class="o">.</span><span class="n">print_atom</span><span class="p">(</span><span class="n">idx</span><span class="p">)</span>
            <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_redraw_hook</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atoms</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="s1">&#39;properties&#39;</span><span class="p">):</span>
           <span class="nb">print</span> <span class="s1">&#39;Properties:&#39;</span>
           <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span>  <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
               <span class="nb">print</span> <span class="s1">&#39;</span><span class="si">%-10s</span><span class="s1"> shape </span><span class="si">%r</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="s1">&#39;params&#39;</span><span class="p">):</span>
           <span class="nb">print</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Params:&#39;</span>
           <span class="k">for</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
               <span class="nb">print</span> <span class="s1">&#39;</span><span class="si">%-20s</span><span class="s1"> = </span><span class="si">%r</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">):</span>
            <span class="nb">print</span> <span class="s1">&#39;</span><span class="si">%-20s</span><span class="s1"> = </span><span class="si">%r</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="s1">&#39;source&#39;</span><span class="p">,</span> <span class="n">atoms</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>

<div class="viewcode-block" id="QuippyViewer.show"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer.show">[docs]</a>    <span class="k">def</span> <span class="nf">show</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">property</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">arrows</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Update what is shown in this AtomEye viewer window.</span>

<span class="sd">        `property` should be the name of the auxiliary property used to colour the atoms (e.g. &quot;charge&quot;)</span>
<span class="sd">        `frame` is the (zero-based) index of the frame to show.</span>
<span class="sd">        `arrows` is the name of a vector property to use to draw arrows on the atoms (e.g. &quot;force&quot;)</span>

<span class="sd">        When called with no arguments, show() is equivalent to redraw().</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">AtomEyeViewer</span><span class="o">.</span><span class="n">show</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="nb">property</span><span class="p">,</span> <span class="n">frame</span><span class="p">,</span> <span class="n">arrows</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="QuippyViewer.clip_visible"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer.clip_visible">[docs]</a>    <span class="k">def</span> <span class="nf">clip_visible</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">orig_index</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Remove atoms outside the visible window from the Atoms object. Also sets indices for frames not yet loaded from disk.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">indices</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_visible</span><span class="p">()</span>
        <span class="nb">print</span> <span class="s1">&#39;Clipping view to include </span><span class="si">%d</span><span class="s1"> atoms&#39;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">indices</span><span class="p">)</span>

        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcat</span><span class="p">()</span>
        <span class="n">mask</span> <span class="o">=</span> <span class="n">fzeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">at</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">bool</span><span class="p">)</span>
        <span class="n">mask</span><span class="p">[:]</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="n">mask</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">at</span><span class="o">.</span><span class="n">remove_atoms</span><span class="p">(</span><span class="n">mask</span><span class="o">=</span><span class="n">mask</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">orig_index</span><span class="p">:</span>
            <span class="n">at</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="s1">&#39;orig_index&#39;</span><span class="p">,</span>
                            <span class="n">logical_not</span><span class="p">(</span><span class="n">mask</span><span class="p">)</span><span class="o">.</span><span class="n">nonzero</span><span class="p">()[</span><span class="mi">0</span><span class="p">],</span>
                            <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;reader&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="p">,</span> <span class="n">CInOutputReader</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="n">indices</span>
        <span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;reader&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="p">,</span> <span class="s1">&#39;__iter__&#39;</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">readers</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="s1">&#39;reader&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">reader</span><span class="p">,</span> <span class="n">CInOutputReader</span><span class="p">):</span>
                    <span class="n">r</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">indices</span> <span class="o">=</span> <span class="n">indices</span></div>

<div class="viewcode-block" id="QuippyViewer.select_atoms"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer.select_atoms">[docs]</a>    <span class="k">def</span> <span class="nf">select_atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reset</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">markname</span><span class="o">=</span><span class="s1">&#39;selection_mark&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Select atoms by clicking on them. Returns a list of atom indices.</span>

<span class="sd">        Specify reset=False to modify an existing property. The name of the</span>
<span class="sd">        property is `markname` (default &quot;selection_mark&quot;) and the value of</span>
<span class="sd">        clicked atoms is given by the `value` argument (default True).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcat</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">reset</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">at</span><span class="o">.</span><span class="n">has_property</span><span class="p">(</span><span class="n">markname</span><span class="p">):</span>
            <span class="n">at</span><span class="o">.</span><span class="n">add_property</span><span class="p">(</span><span class="n">markname</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span> <span class="o">=</span> <span class="n">markname</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_selection_value</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">show</span><span class="p">(</span><span class="n">markname</span><span class="p">)</span>
        <span class="n">saved_verbose</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="nb">print</span> <span class="s1">&#39;Right click to select atoms. Press ENTER to finish.&#39;</span>
        <span class="nb">print</span> <span class="s1">&#39;indices = [&#39;</span><span class="p">,</span>
        <span class="n">raw_input</span><span class="p">()</span>
        <span class="nb">print</span> <span class="s1">&#39;]&#39;</span>
        <span class="n">indices</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span><span class="p">]</span><span class="o">.</span><span class="n">nonzero</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_selection_markname</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">=</span> <span class="n">saved_verbose</span>
        <span class="k">return</span> <span class="n">indices</span></div>

<div class="viewcode-block" id="QuippyViewer.render_movie"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer.render_movie">[docs]</a>    <span class="k">def</span> <span class="nf">render_movie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">moviefile</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">hook</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                     <span class="n">offset</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="s1">&#39;ffmpeg -i </span><span class="si">%s</span><span class="s1"> -r 25 -b 30M </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Render a movie for the trajectory.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">start</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">stop</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">step</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">frames</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="o">*</span><span class="nb">slice</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span><span class="o">.</span><span class="n">indices</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">)))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">frames</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>

        <span class="n">basename</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">moviefile</span><span class="p">)</span>
        <span class="n">out_fmt</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s%%</span><span class="s1">05d.jpg&#39;</span> <span class="o">%</span> <span class="n">basename</span>
        
        <span class="k">for</span> <span class="n">frame</span> <span class="ow">in</span> <span class="n">frames</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">show</span><span class="p">(</span><span class="n">frame</span><span class="o">=</span><span class="n">frame</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">hook</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
                <span class="n">hook</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">gcat</span><span class="p">())</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">capture</span><span class="p">(</span><span class="n">out_fmt</span> <span class="o">%</span> <span class="p">(</span><span class="n">frame</span> <span class="o">+</span> <span class="n">offset</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="nb">print</span> <span class="s1">&#39;Encoding movie...&#39;</span>
        <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="n">encoder</span> <span class="o">%</span> <span class="p">(</span><span class="n">out_fmt</span><span class="p">,</span> <span class="n">moviefile</span><span class="p">))</span></div>

    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">atoms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">recycle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">inject</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__getinitargs__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="p">,</span> <span class="s1">&#39;filename&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">filename</span><span class="p">,)</span>
        <span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;can&#39;t work out how to pickle Atoms&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__getstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">state</span> <span class="o">=</span> <span class="n">AtomEyeViewer</span><span class="o">.</span><span class="n">__getstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">state</span>

    <span class="k">def</span> <span class="nf">__setstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state</span><span class="p">):</span>
        <span class="n">AtomEyeViewer</span><span class="o">.</span><span class="n">__setstate__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state</span><span class="p">)</span>

<div class="viewcode-block" id="QuippyViewer.set_cutoffs"><a class="viewcode-back" href="../qlab.html#qlab.QuippyViewer.set_cutoffs">[docs]</a>    <span class="k">def</span> <span class="nf">set_cutoffs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nneighb_only</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set cutoffs for AtomEye bonds and coordination colouring</span>

<span class="sd">        Cutoff lengths are set to match quippy :attr:`~atoms.Atoms.nneightol`</span>
<span class="sd">        (if `nneighb_only` is True, the default) or :attr:`~atoms.Atoms.cutoff`</span>
<span class="sd">        (otherwise).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">at</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcat</span><span class="p">()</span>
        <span class="n">seen</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">Z1</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">z</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">Z2</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">z</span><span class="p">):</span>
                <span class="k">if</span> <span class="p">(</span><span class="nb">min</span><span class="p">(</span><span class="n">Z1</span><span class="p">,</span><span class="n">Z2</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">Z1</span><span class="p">,</span> <span class="n">Z2</span><span class="p">))</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">seen</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="nb">min</span><span class="p">(</span><span class="n">Z1</span><span class="p">,</span> <span class="n">Z2</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">Z1</span><span class="p">,</span> <span class="n">Z2</span><span class="p">)))</span>
                <span class="n">sym1</span><span class="p">,</span> <span class="n">sym2</span> <span class="o">=</span> <span class="n">ElementName</span><span class="p">[</span><span class="n">Z1</span><span class="p">],</span> <span class="n">ElementName</span><span class="p">[</span><span class="n">Z2</span><span class="p">]</span>
                <span class="nb">print</span> <span class="n">sym1</span><span class="p">,</span> <span class="n">sym2</span><span class="p">,</span> 
                <span class="k">if</span> <span class="n">nneighb_only</span><span class="p">:</span>
                    <span class="n">cutoff</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">nneightol</span><span class="o">*</span><span class="n">bond_length</span><span class="p">(</span><span class="n">Z1</span><span class="p">,</span> <span class="n">Z2</span><span class="p">)</span>
                    <span class="nb">print</span> <span class="s1">&#39;nneigbb&#39;</span><span class="p">,</span> <span class="n">cutoff</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">cutoff</span> <span class="o">=</span> <span class="n">at</span><span class="o">.</span><span class="n">cutoff</span>
                    <span class="nb">print</span> <span class="s1">&#39;uniform&#39;</span><span class="p">,</span> <span class="n">cutoff</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">rcut_patch</span><span class="p">(</span><span class="n">sym1</span><span class="p">,</span> <span class="n">sym2</span><span class="p">,</span> <span class="n">cutoff</span><span class="p">,</span> <span class="n">absolute</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div></div>
    

<div class="viewcode-block" id="AtomsViewer"><a class="viewcode-back" href="../qlab.html#qlab.AtomsViewer">[docs]</a><span class="k">class</span> <span class="nc">AtomsViewer</span><span class="p">(</span><span class="n">Atoms</span><span class="p">,</span> <span class="n">QuippyViewer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of Atoms and AtomEyeViewer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">Atoms</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Atoms</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">shallow_copy_from</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_from</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">QuippyViewer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<div class="viewcode-block" id="AtomsViewer.gcat"><a class="viewcode-back" href="../qlab.html#qlab.AtomsViewer.gcat">[docs]</a>    <span class="k">def</span> <span class="nf">gcat</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">update</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span></div>

<div class="viewcode-block" id="AtomsViewer.scat"><a class="viewcode-back" href="../qlab.html#qlab.AtomsViewer.scat">[docs]</a>    <span class="k">def</span> <span class="nf">scat</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atoms</span><span class="p">,</span> <span class="n">frame</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">pass</span></div>

    <span class="k">def</span> <span class="nf">update_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Atoms</span><span class="p">):</span>
            <span class="n">source</span> <span class="o">=</span> <span class="n">Atoms</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shallow_copy_from</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">reload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update_source</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>

<div class="viewcode-block" id="AtomsViewer.copy"><a class="viewcode-back" href="../qlab.html#qlab.AtomsViewer.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">Atoms</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="AtomsReaderViewer"><a class="viewcode-back" href="../qlab.html#qlab.AtomsReaderViewer">[docs]</a><span class="k">class</span> <span class="nc">AtomsReaderViewer</span><span class="p">(</span><span class="n">AtomsReader</span><span class="p">,</span> <span class="n">QuippyViewer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of AtomsReader and AtomEyeViewer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">cache</span><span class="p">:</span>
            <span class="n">total_mem</span><span class="p">,</span> <span class="n">free_mem</span> <span class="o">=</span> <span class="n">mem_info</span><span class="p">()</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;cache_mem_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.5</span><span class="o">*</span><span class="n">free_mem</span>
        <span class="n">AtomsReader</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="n">rename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">QuippyViewer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">update_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">cache</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">cache</span><span class="p">:</span>
            <span class="n">total_mem</span><span class="p">,</span> <span class="n">free_mem</span> <span class="o">=</span> <span class="n">mem_info</span><span class="p">()</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;cache_mem_limit&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.5</span><span class="o">*</span><span class="n">free_mem</span>
        <span class="n">AtomsReader</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">reload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update_source</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">last</span><span class="p">()</span></div>


<div class="viewcode-block" id="AtomsListViewer"><a class="viewcode-back" href="../qlab.html#qlab.AtomsListViewer">[docs]</a><span class="k">class</span> <span class="nc">AtomsListViewer</span><span class="p">(</span><span class="n">AtomsList</span><span class="p">,</span> <span class="n">QuippyViewer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of AtomsList and AtomEyeViewer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">AtomsList</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="n">rename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">QuippyViewer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">update_source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">del</span> <span class="bp">self</span><span class="p">[:]</span>
        <span class="n">AtomsList</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">reload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update_source</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">last</span><span class="p">()</span></div>


<span class="k">def</span> <span class="nf">find_viewer</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">recycle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="k">global</span> <span class="n">_viewers</span><span class="p">,</span> <span class="n">_current_viewer</span>

    <span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">name</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">basestring</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">source</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">,</span><span class="s1">&#39;_&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span><span class="s1">&#39;_&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;*&#39;</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;?&#39;</span><span class="p">,</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="s1">&#39;__iter__&#39;</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;al&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;at&#39;</span>

    <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">_viewers</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">recycle</span><span class="p">:</span>
        <span class="c1"># find a unique name</span>
        <span class="n">n</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">new_name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="k">while</span> <span class="n">new_name</span> <span class="ow">in</span> <span class="n">_viewers</span><span class="p">:</span>
            <span class="n">n</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">new_name</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">_</span><span class="si">%d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">new_name</span>

    <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">_viewers</span><span class="p">:</span>
        <span class="nb">print</span> <span class="s1">&#39;Reusing viewer named </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">name</span>
        <span class="n">scv</span><span class="p">(</span><span class="n">_viewers</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">_viewers</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="nb">print</span> <span class="s1">&#39;Creating viewer named </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">name</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        

<div class="viewcode-block" id="view"><a class="viewcode-back" href="../qlab.html#qlab.view">[docs]</a><span class="k">def</span> <span class="nf">view</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">recycle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">loadall</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">inject</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
         <span class="n">rename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Read atoms from `source` and open in an AtomEye viewer window.</span>

<span class="sd">    If not present, `name` is derived from the filename of `source`.</span>

<span class="sd">    If recycle is true (default), try to reuse an exising viewer window</span>
<span class="sd">    with the same name. Otherwise the name is made unique if necesary</span>
<span class="sd">    by appending a number.</span>

<span class="sd">    If loadall is false (default) we use an AtomsReader to load the</span>
<span class="sd">    frames from the trajectory lazily (i.e., as required). Otherwise</span>
<span class="sd">    the entire file is read into an AtomsList.</span>

<span class="sd">    If inject is true (default), a new variable called `name` is injected</span>
<span class="sd">    into the parent stack frame.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">viewer</span> <span class="o">=</span> <span class="n">find_viewer</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">recycle</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">viewer</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">tmp_reader</span> <span class="o">=</span> <span class="n">AtomsReader</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="n">rename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Atoms</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">tmp_reader</span><span class="o">.</span><span class="n">random_access</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp_reader</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">):</span>
            <span class="n">viewer</span> <span class="o">=</span> <span class="n">AtomsViewer</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">loadall</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">tmp_reader</span><span class="o">.</span><span class="n">random_access</span><span class="p">:</span>
                <span class="n">viewer</span> <span class="o">=</span> <span class="n">AtomsListViewer</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                         <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">viewer</span> <span class="o">=</span> <span class="n">AtomsReaderViewer</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="n">rename</span><span class="p">,</span>
                                           <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">viewer</span><span class="o">.</span><span class="n">update_source</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">inject</span><span class="p">:</span>
        <span class="n">parent_frame</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">currentframe</span><span class="p">()</span><span class="o">.</span><span class="n">f_back</span>
        <span class="n">parent_frame</span><span class="o">.</span><span class="n">f_globals</span><span class="p">[</span><span class="n">viewer</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">viewer</span>
    <span class="k">return</span> <span class="n">viewer</span></div>


<div class="viewcode-block" id="gcv"><a class="viewcode-back" href="../qlab.html#qlab.gcv">[docs]</a><span class="k">def</span> <span class="nf">gcv</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return the current (most recently created or used) AtomEye viewer instance</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">_current_viewer</span>
    <span class="k">if</span> <span class="n">_current_viewer</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;No viewers are currently open!&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">_current_viewer</span></div>

<div class="viewcode-block" id="gcat"><a class="viewcode-back" href="../qlab.html#qlab.gcat">[docs]</a><span class="k">def</span> <span class="nf">gcat</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return the current Atoms object being visualised by the current viewer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">gcat</span><span class="p">()</span></div>

<div class="viewcode-block" id="scv"><a class="viewcode-back" href="../qlab.html#qlab.scv">[docs]</a><span class="k">def</span> <span class="nf">scv</span><span class="p">(</span><span class="n">viewer</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set the current AtomEye viewer to `viewer`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">_current_viewer</span>
    <span class="n">_current_viewer</span> <span class="o">=</span> <span class="n">viewer</span></div>

<div class="viewcode-block" id="get_viewer"><a class="viewcode-back" href="../qlab.html#qlab.get_viewer">[docs]</a><span class="k">def</span> <span class="nf">get_viewer</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return the viewer identified by `name`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">_viewers</span>
    <span class="k">return</span> <span class="n">_viewers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span></div>

<div class="viewcode-block" id="get_viewer_names"><a class="viewcode-back" href="../qlab.html#qlab.get_viewer_names">[docs]</a><span class="k">def</span> <span class="nf">get_viewer_names</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return the current list of viewer names</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">_viewers</span>
    <span class="k">return</span> <span class="n">_viewers</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span></div>

<div class="viewcode-block" id="get_viewers"><a class="viewcode-back" href="../qlab.html#qlab.get_viewers">[docs]</a><span class="k">def</span> <span class="nf">get_viewers</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return the current list of viewers</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">_viewers</span>
    <span class="k">return</span> <span class="n">_viewers</span><span class="o">.</span><span class="n">values</span><span class="p">()</span></div>

<div class="viewcode-block" id="highlight_qm_region"><a class="viewcode-back" href="../qlab.html#qlab.highlight_qm_region">[docs]</a><span class="k">def</span> <span class="nf">highlight_qm_region</span><span class="p">(</span><span class="n">at</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">run_suffix</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Highlight QM region by replacing Si atoms with Al,</span>
<span class="sd">    and O atoms with N, and changing colour of QM atoms to dark blue. Can be used as</span>
<span class="sd">    a hook function to render_movie().</span>

<span class="sd">    If at is None, uses Atoms associated with current viewer</span>
<span class="sd">    (i.e., at = gcat()).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">at</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">at</span> <span class="o">=</span> <span class="n">gcat</span><span class="p">()</span>
    <span class="n">hybrid_mark</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">at</span><span class="p">,</span> <span class="s1">&#39;hybrid_mark&#39;</span><span class="o">+</span><span class="n">run_suffix</span><span class="p">)</span>
    <span class="n">at</span><span class="o">.</span><span class="n">z</span><span class="p">[(</span><span class="n">at</span><span class="o">.</span><span class="n">z</span> <span class="o">==</span> <span class="mi">14</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">hybrid_mark</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)]</span> <span class="o">=</span> <span class="mi">13</span>
    <span class="n">at</span><span class="o">.</span><span class="n">z</span><span class="p">[(</span><span class="n">at</span><span class="o">.</span><span class="n">z</span> <span class="o">==</span> <span class="mi">8</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">hybrid_mark</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)]</span> <span class="o">=</span> <span class="mi">7</span>
    <span class="n">at</span><span class="o">.</span><span class="n">set_atoms</span><span class="p">(</span><span class="n">at</span><span class="o">.</span><span class="n">z</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">highlight_qm_region</span><span class="o">.</span><span class="n">first_time</span><span class="p">:</span>
        <span class="n">save_block</span> <span class="o">=</span> <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">block</span>
        <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">block</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="n">redraw</span><span class="p">()</span>
        <span class="n">rcut_patch</span><span class="p">(</span><span class="s1">&#39;Si&#39;</span><span class="p">,</span> <span class="s1">&#39;Si&#39;</span><span class="p">,</span> <span class="o">+</span><span class="mf">0.3</span><span class="p">)</span>
        <span class="n">rcut_patch</span><span class="p">(</span><span class="s1">&#39;Al&#39;</span><span class="p">,</span> <span class="s1">&#39;Al&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.55</span><span class="p">)</span>
        <span class="n">run_command</span><span class="p">(</span><span class="s1">&#39;change_normal_color 13 0.0 0.0 0.7 1.2&#39;</span><span class="p">)</span>
        <span class="n">run_command</span><span class="p">(</span><span class="s1">&#39;change_normal_color 5 0.9 0.4 0 1.5&#39;</span><span class="p">)</span>
        <span class="n">run_command</span><span class="p">(</span><span class="s1">&#39;change_normal_color 7 0.0 0.7 0.7 0.7&#39;</span><span class="p">)</span>
        <span class="n">highlight_qm_region</span><span class="o">.</span><span class="n">first_time</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">block</span> <span class="o">=</span> <span class="n">save_block</span>
    <span class="n">redraw</span><span class="p">()</span></div>

<span class="n">highlight_qm_region</span><span class="o">.</span><span class="n">first_time</span> <span class="o">=</span> <span class="kc">True</span>

<div class="viewcode-block" id="redraw"><a class="viewcode-back" href="../qlab.html#qlab.redraw">[docs]</a><span class="k">def</span> <span class="nf">redraw</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Redraw current AtomEye window, keeping Atoms and settings the same.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">redraw</span><span class="p">()</span></div>

<div class="viewcode-block" id="run_command"><a class="viewcode-back" href="../qlab.html#qlab.run_command">[docs]</a><span class="k">def</span> <span class="nf">run_command</span><span class="p">(</span><span class="n">command</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run a command in current AtomEye thread.</span>

<span class="sd">    The command is queued for later execution, unless :attr:`block` is True.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>

<span class="sd">    command : string</span>
<span class="sd">       The command to pass to AtomEye</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">run_command</span><span class="p">(</span><span class="n">command</span><span class="p">)</span></div>

<div class="viewcode-block" id="run_script"><a class="viewcode-back" href="../qlab.html#qlab.run_script">[docs]</a><span class="k">def</span> <span class="nf">run_script</span><span class="p">(</span><span class="n">script</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run commands from the file script, in a blocking fashion.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">run_script</span><span class="p">(</span><span class="n">script</span><span class="p">)</span></div>

<div class="viewcode-block" id="close"><a class="viewcode-back" href="../qlab.html#qlab.close">[docs]</a><span class="k">def</span> <span class="nf">close</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Close the current viewer window.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="setp"><a class="viewcode-back" href="../qlab.html#qlab.setp">[docs]</a><span class="k">def</span> <span class="nf">setp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Run the AtomEye command &quot;set key value&quot;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div>

<div class="viewcode-block" id="save_script"><a class="viewcode-back" href="../qlab.html#qlab.save_script">[docs]</a><span class="k">def</span> <span class="nf">save_script</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Save AtomEye viewer settings to a file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="toggle_coordination_coloring"><a class="viewcode-back" href="../qlab.html#qlab.toggle_coordination_coloring">[docs]</a><span class="k">def</span> <span class="nf">toggle_coordination_coloring</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Turn on or off colouring by coordination number (key &quot;k&quot;)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_coordination_coloring</span><span class="p">()</span></div>

<div class="viewcode-block" id="translate"><a class="viewcode-back" href="../qlab.html#qlab.translate">[docs]</a><span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Translate system along `axis` by an amount `delta` (key &quot;Ctrl+left/right/up/down&quot;)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="shift_xtal"><a class="viewcode-back" href="../qlab.html#qlab.shift_xtal">[docs]</a><span class="k">def</span> <span class="nf">shift_xtal</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Shift crystal within periodic boundaries along `axis` by `delta` (key &quot;Shift+left/right/up/down&quot;).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">shift_xtal</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="rotate"><a class="viewcode-back" href="../qlab.html#qlab.rotate">[docs]</a><span class="k">def</span> <span class="nf">rotate</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">theta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Rotate around `axis` by angle `theta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">theta</span><span class="p">)</span></div>

<div class="viewcode-block" id="advance"><a class="viewcode-back" href="../qlab.html#qlab.advance">[docs]</a><span class="k">def</span> <span class="nf">advance</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Move the camera forward by `delta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">advance</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="shift_cutting_plane"><a class="viewcode-back" href="../qlab.html#qlab.shift_cutting_plane">[docs]</a><span class="k">def</span> <span class="nf">shift_cutting_plane</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Shift the current cutting plane by an amount `delta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">shift_cutting_plane</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_bgcolor"><a class="viewcode-back" href="../qlab.html#qlab.change_bgcolor">[docs]</a><span class="k">def</span> <span class="nf">change_bgcolor</span><span class="p">(</span><span class="n">color</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the viewer background colour to `color`, which should be a RGB tuple with three floats in range 0..1.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_bgcolor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_atom_r_ratio"><a class="viewcode-back" href="../qlab.html#qlab.change_atom_r_ratio">[docs]</a><span class="k">def</span> <span class="nf">change_atom_r_ratio</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the size of the balls used to draw the atoms by `delta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_atom_r_ratio</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_bond_radius"><a class="viewcode-back" href="../qlab.html#qlab.change_bond_radius">[docs]</a><span class="k">def</span> <span class="nf">change_bond_radius</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the radius of the cylinders used the draw bonds by `delta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_bond_radius</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_view_angle_amplification"><a class="viewcode-back" href="../qlab.html#qlab.change_view_angle_amplification">[docs]</a><span class="k">def</span> <span class="nf">change_view_angle_amplification</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the amplification of the view angle by `delta`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_view_angle_amplification</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="toggle_parallel_projection"><a class="viewcode-back" href="../qlab.html#qlab.toggle_parallel_projection">[docs]</a><span class="k">def</span> <span class="nf">toggle_parallel_projection</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Toggle between parallel and perspective projections.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_parallel_projection</span><span class="p">()</span></div>

<div class="viewcode-block" id="toggle_bond_mode"><a class="viewcode-back" href="../qlab.html#qlab.toggle_bond_mode">[docs]</a><span class="k">def</span> <span class="nf">toggle_bond_mode</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Turn on or off bonds.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_bond_mode</span><span class="p">()</span></div>

<div class="viewcode-block" id="toggle_small_cell_mode"><a class="viewcode-back" href="../qlab.html#qlab.toggle_small_cell_mode">[docs]</a><span class="k">def</span> <span class="nf">toggle_small_cell_mode</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Toggle between two different behaviours for when cell is smaller than r_cut/2:</span>
<span class="sd">     1. clip cell - some neigbours may be lost (default)</span>
<span class="sd">     2. replicate cell along narrow directions</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_small_cell_mode</span><span class="p">()</span></div>

<div class="viewcode-block" id="normal_coloring"><a class="viewcode-back" href="../qlab.html#qlab.normal_coloring">[docs]</a><span class="k">def</span> <span class="nf">normal_coloring</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return to normal colouring of the atoms (key &quot;o&quot;).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">normal_coloring</span><span class="p">()</span></div>

<div class="viewcode-block" id="aux_property_coloring"><a class="viewcode-back" href="../qlab.html#qlab.aux_property_coloring">[docs]</a><span class="k">def</span> <span class="nf">aux_property_coloring</span><span class="p">(</span><span class="n">auxprop</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Colour the currently viewed atoms according to `auxprop`.</span>

<span class="sd">    Overloaded to allow </span>
<span class="sd">    See :ref:`qlab_atom_coloring` for more details and examples.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    auxprop : str, array_like, int or list</span>
<span class="sd">       Values to use to colour the atoms. Should be either the</span>
<span class="sd">       name of a scalar field entry in :attr:`~.Atoms.properties`</span>
<span class="sd">       (or equivalently, :attr:`~Atoms.arrays`) such as ``&quot;charge&quot;``,</span>
<span class="sd">       a float, int or bool array of shape ``(len(gcat()),)``, or an</span>
<span class="sd">       atom index or list of atom indices to highlight particular atoms.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">aux_property_coloring</span><span class="p">(</span><span class="n">auxprop</span><span class="p">)</span></div>

<div class="viewcode-block" id="central_symmetry_coloring"><a class="viewcode-back" href="../qlab.html#qlab.central_symmetry_coloring">[docs]</a><span class="k">def</span> <span class="nf">central_symmetry_coloring</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Colour atoms by centro-symmetry parameter.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">central_symmetry_coloring</span><span class="p">()</span></div>

<div class="viewcode-block" id="change_aux_property_threshold"><a class="viewcode-back" href="../qlab.html#qlab.change_aux_property_threshold">[docs]</a><span class="k">def</span> <span class="nf">change_aux_property_threshold</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">upper</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the lower and upper aux property thresholds.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_aux_property_threshold</span><span class="p">(</span><span class="n">lower</span><span class="p">,</span> <span class="n">upper</span><span class="p">)</span></div>

<div class="viewcode-block" id="reset_aux_property_thresholds"><a class="viewcode-back" href="../qlab.html#qlab.reset_aux_property_thresholds">[docs]</a><span class="k">def</span> <span class="nf">reset_aux_property_thresholds</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Reset aux property thresholds to automatic values.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">reset_aux_property_thresholds</span><span class="p">()</span></div>

<div class="viewcode-block" id="toggle_aux_property_thresholds_saturation"><a class="viewcode-back" href="../qlab.html#qlab.toggle_aux_property_thresholds_saturation">[docs]</a><span class="k">def</span> <span class="nf">toggle_aux_property_thresholds_saturation</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Toggle between saturated colouring and invisibility for values outside aux prop thresholds.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_aux_property_thresholds_saturation</span><span class="p">()</span></div>

<div class="viewcode-block" id="toggle_aux_property_thresholds_rigid"><a class="viewcode-back" href="../qlab.html#qlab.toggle_aux_property_thresholds_rigid">[docs]</a><span class="k">def</span> <span class="nf">toggle_aux_property_thresholds_rigid</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Toggle between floating and rigid aux property thresholds when moving between frames</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">toggle_aux_property_thresholds_rigid</span><span class="p">()</span></div>

<div class="viewcode-block" id="rcut_patch"><a class="viewcode-back" href="../qlab.html#qlab.rcut_patch">[docs]</a><span class="k">def</span> <span class="nf">rcut_patch</span><span class="p">(</span><span class="n">sym1</span><span class="p">,</span> <span class="n">sym2</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">absolute</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the cutoff distance for `sym1`--`sym2` bonds by `delta`.</span>

<span class="sd">    e.g. to increase cutoff for Si-Si bonds by 0.5 A use::</span>

<span class="sd">         viewer.rcut_patch(&#39;Si&#39;, &#39;Si&#39;, 0.5)</span>

<span class="sd">    With `absolute` set to True, `value` is used to set the</span>
<span class="sd">    absolute cutoff distance for `sym1`--`sym2` bonds, e.g.::</span>

<span class="sd">         viewer.rcut_patch(&#39;Si&#39;, &#39;Si&#39;, 2.50, True)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">rcut_patch</span><span class="p">(</span><span class="n">sym1</span><span class="p">,</span> <span class="n">sym2</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">absolute</span><span class="p">)</span></div>

<div class="viewcode-block" id="select_gear"><a class="viewcode-back" href="../qlab.html#qlab.select_gear">[docs]</a><span class="k">def</span> <span class="nf">select_gear</span><span class="p">(</span><span class="n">gear</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the AtomEye gear to `gear`</span>

<span class="sd">    Equivalent to pressing the one of the numeric keys 0..9</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">select_gear</span><span class="p">(</span><span class="n">gear</span><span class="p">)</span></div>

<div class="viewcode-block" id="cutting_plane"><a class="viewcode-back" href="../qlab.html#qlab.cutting_plane">[docs]</a><span class="k">def</span> <span class="nf">cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a new cutting plane with index `n`, normal `d`, and fractional displacement `s`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span></div>

<div class="viewcode-block" id="shift_cutting_plane_to_anchor"><a class="viewcode-back" href="../qlab.html#qlab.shift_cutting_plane_to_anchor">[docs]</a><span class="k">def</span> <span class="nf">shift_cutting_plane_to_anchor</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Move the cutting plane with index `n` to the anchor</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">shift_cutting_plane_to_anchor</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<div class="viewcode-block" id="delete_cutting_plane"><a class="viewcode-back" href="../qlab.html#qlab.delete_cutting_plane">[docs]</a><span class="k">def</span> <span class="nf">delete_cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Delete the cutting plane with index `n`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">delete_cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<div class="viewcode-block" id="flip_cutting_plane"><a class="viewcode-back" href="../qlab.html#qlab.flip_cutting_plane">[docs]</a><span class="k">def</span> <span class="nf">flip_cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Flip the cutting plane with index `n`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">flip_cutting_plane</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<div class="viewcode-block" id="capture"><a class="viewcode-back" href="../qlab.html#qlab.capture">[docs]</a><span class="k">def</span> <span class="nf">capture</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">resolution</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Render the current view to image `filename`</span>

<span class="sd">    Format is determined from file extension: .png, .jpeg, or .eps.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">capture</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">resolution</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_wireframe_mode"><a class="viewcode-back" href="../qlab.html#qlab.change_wireframe_mode">[docs]</a><span class="k">def</span> <span class="nf">change_wireframe_mode</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the display mode for the unit cell box.</span>

<span class="sd">    Equivalent to pressing the `i` key.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_wireframe_mode</span><span class="p">()</span></div>

<div class="viewcode-block" id="change_cutting_plane_wireframe_mode"><a class="viewcode-back" href="../qlab.html#qlab.change_cutting_plane_wireframe_mode">[docs]</a><span class="k">def</span> <span class="nf">change_cutting_plane_wireframe_mode</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Change the display mode for cutting planes</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_cutting_plane_wireframe_mode</span><span class="p">()</span></div>

<div class="viewcode-block" id="get_frame"><a class="viewcode-back" href="../qlab.html#qlab.get_frame">[docs]</a><span class="k">def</span> <span class="nf">get_frame</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Get index of frame currently being viewed</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">frame</span></div>

<div class="viewcode-block" id="set_frame"><a class="viewcode-back" href="../qlab.html#qlab.set_frame">[docs]</a><span class="k">def</span> <span class="nf">set_frame</span><span class="p">(</span><span class="n">frame</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set current frame index to `frame`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">frame</span> <span class="o">=</span> <span class="n">frame</span></div>

<div class="viewcode-block" id="get_delta"><a class="viewcode-back" href="../qlab.html#qlab.get_delta">[docs]</a><span class="k">def</span> <span class="nf">get_delta</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Get frame increment rate</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">delta</span></div>

<div class="viewcode-block" id="set_delta"><a class="viewcode-back" href="../qlab.html#qlab.set_delta">[docs]</a><span class="k">def</span> <span class="nf">set_delta</span><span class="p">(</span><span class="n">delta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set frame increment rate</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="n">delta</span></div>

<div class="viewcode-block" id="first"><a class="viewcode-back" href="../qlab.html#qlab.first">[docs]</a><span class="k">def</span> <span class="nf">first</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Show the first frame (frame 0).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">first</span><span class="p">()</span></div>

<div class="viewcode-block" id="last"><a class="viewcode-back" href="../qlab.html#qlab.last">[docs]</a><span class="k">def</span> <span class="nf">last</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Show the last frame, i.e. len(gcv())-1</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">first</span><span class="p">()</span></div>

<div class="viewcode-block" id="forward"><a class="viewcode-back" href="../qlab.html#qlab.forward">[docs]</a><span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="n">delta</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Move forward by `delta` frames (default value is gcv().delta).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="backward"><a class="viewcode-back" href="../qlab.html#qlab.backward">[docs]</a><span class="k">def</span> <span class="nf">backward</span><span class="p">(</span><span class="n">delta</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Move backward by `delta` frames (default values is gcv().delta).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">backward</span><span class="p">(</span><span class="n">delta</span><span class="p">)</span></div>

<div class="viewcode-block" id="load_atom_color"><a class="viewcode-back" href="../qlab.html#qlab.load_atom_color">[docs]</a><span class="k">def</span> <span class="nf">load_atom_color</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Load atom colours from a .clr file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">load_atom_color</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="load_aux"><a class="viewcode-back" href="../qlab.html#qlab.load_aux">[docs]</a><span class="k">def</span> <span class="nf">load_aux</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Load aux property values from a .aux file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">load_aux</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="look_at_the_anchor"><a class="viewcode-back" href="../qlab.html#qlab.look_at_the_anchor">[docs]</a><span class="k">def</span> <span class="nf">look_at_the_anchor</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Equivalent to pressing the `a` key</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">look_at_the_anchor</span><span class="p">()</span></div>

<div class="viewcode-block" id="observer_goto"><a class="viewcode-back" href="../qlab.html#qlab.observer_goto">[docs]</a><span class="k">def</span> <span class="nf">observer_goto</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Prompt for fractional position and move the observer there</span>

<span class="sd">    Equivalent to pressing the `g` key.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">observer_goto</span><span class="p">()</span></div>

<div class="viewcode-block" id="xtal_origin_goto"><a class="viewcode-back" href="../qlab.html#qlab.xtal_origin_goto">[docs]</a><span class="k">def</span> <span class="nf">xtal_origin_goto</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Move the crystal origin to fractional coordinates `s`</span>

<span class="sd">    For example, use ``s=[0.5, 0.5, 0.5]`` to shift by half the cell along</span>
<span class="sd">    the :math:`\mathbf{a}`, :math:`\mathbf{b}` and :math:`\mathbf{c}`</span>
<span class="sd">    lattice vectors.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">xtal_origin_goto</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></div>

<div class="viewcode-block" id="find_atom"><a class="viewcode-back" href="../qlab.html#qlab.find_atom">[docs]</a><span class="k">def</span> <span class="nf">find_atom</span><span class="p">(</span><span class="n">i</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set the anchor to the atom with index `i`.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">find_atom</span><span class="p">(</span><span class="n">i</span><span class="p">)</span></div>

<div class="viewcode-block" id="resize"><a class="viewcode-back" href="../qlab.html#qlab.resize">[docs]</a><span class="k">def</span> <span class="nf">resize</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Resize the current window to `width` x `height` pixels.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">)</span></div>

<div class="viewcode-block" id="change_aux_colormap"><a class="viewcode-back" href="../qlab.html#qlab.change_aux_colormap">[docs]</a><span class="k">def</span> <span class="nf">change_aux_colormap</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Select the `n`\ -th auxiliary property colourmap. </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">change_aux_colormap</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></div>

<div class="viewcode-block" id="draw_arrows"><a class="viewcode-back" href="../qlab.html#qlab.draw_arrows">[docs]</a><span class="k">def</span> <span class="nf">draw_arrows</span><span class="p">(</span><span class="nb">property</span><span class="p">,</span> <span class="n">scale_factor</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">head_height</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span>
                <span class="n">head_width</span><span class="o">=</span><span class="mf">0.05</span><span class="p">,</span> <span class="n">up</span><span class="o">=</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span><span class="mf">1.0</span><span class="p">,</span><span class="mf">0.0</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Draw arrows on each atom, based on a vector property</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    property : string</span>
<span class="sd">       Name of the array to use for arrow vectors.</span>
<span class="sd">       Use ``None`` to turn off previous arrows.</span>
<span class="sd">    scale_factor : float</span>
<span class="sd">       Override length of arrows. 1 unit = 1 Angstrom; default</span>
<span class="sd">       value of 0.0 means autoscale.</span>
<span class="sd">    head_height : float</span>
<span class="sd">       Specify height of arrow heads in Angstrom. </span>
<span class="sd">    head_width : float</span>
<span class="sd">    up : 3-vector (tuple, list or array)</span>
<span class="sd">       Specify the plane in which the arrow heads are</span>
<span class="sd">       drawn. Arrows are drawn in the plane which is common</span>
<span class="sd">       to their direction and this vector.</span>
<span class="sd">       Default is ``[0.,1.,0.]``.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">draw_arrows</span><span class="p">(</span><span class="nb">property</span><span class="p">,</span> <span class="n">scale_factor</span><span class="p">,</span> <span class="n">head_height</span><span class="p">,</span>
                      <span class="n">head_width</span><span class="p">,</span> <span class="n">up</span><span class="p">)</span></div>

<div class="viewcode-block" id="wait"><a class="viewcode-back" href="../qlab.html#qlab.wait">[docs]</a><span class="k">def</span> <span class="nf">wait</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Sleep until current AtomEye viewer has finished processing all queued events.&quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span></div>

<div class="viewcode-block" id="get_visible"><a class="viewcode-back" href="../qlab.html#qlab.get_visible">[docs]</a><span class="k">def</span> <span class="nf">get_visible</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Return list of indices of atoms currently visible in the current viewer.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">get_visible</span><span class="p">()</span></div>


<div class="viewcode-block" id="clip_visible"><a class="viewcode-back" href="../qlab.html#qlab.clip_visible">[docs]</a><span class="k">def</span> <span class="nf">clip_visible</span><span class="p">(</span><span class="n">orig_index</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Remove atoms outside the visible window from the Atoms object. Also sets indices for frames not yet loaded from disk.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">clip_visible</span><span class="p">(</span><span class="n">orig_index</span><span class="p">)</span></div>

<div class="viewcode-block" id="select_atoms"><a class="viewcode-back" href="../qlab.html#qlab.select_atoms">[docs]</a><span class="k">def</span> <span class="nf">select_atoms</span><span class="p">(</span><span class="n">reset</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">markname</span><span class="o">=</span><span class="s1">&#39;selection_mark&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Select atoms by clicking on them. Returns a list of atom indices.</span>

<span class="sd">    Specify reset=False to modify an existing property. The name of the</span>
<span class="sd">    property is `markname` (default &quot;selection_mark&quot;) and the value of</span>
<span class="sd">    clicked atoms is given by the `value` argument (default True).</span>

<span class="sd">    See also :ref:`qlab_select_atoms`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">select_atoms</span><span class="p">(</span><span class="n">reset</span><span class="p">,</span> <span class="n">markname</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div>

<div class="viewcode-block" id="render_movie"><a class="viewcode-back" href="../qlab.html#qlab.render_movie">[docs]</a><span class="k">def</span> <span class="nf">render_movie</span><span class="p">(</span><span class="n">moviefile</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">hook</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">offset</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="s1">&#39;ffmpeg -i </span><span class="si">%s</span><span class="s1"> -r 25 -b 30M </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Render a movie for the trajectory.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">render_movie</span><span class="p">(</span><span class="n">moviefile</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">hook</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">encoder</span><span class="p">)</span></div>

<div class="viewcode-block" id="set_cutoffs"><a class="viewcode-back" href="../qlab.html#qlab.set_cutoffs">[docs]</a><span class="k">def</span> <span class="nf">set_cutoffs</span><span class="p">(</span><span class="n">nneighb_only</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Set cutoffs for AtomEye bonds and coordination colouring</span>

<span class="sd">    Cutoff lengths are set to match quippy :attr:`~atoms.Atoms.nneightol`</span>
<span class="sd">    (if `nneighb_only` is True, the default) or :attr:`~atoms.Atoms.cutoff`</span>
<span class="sd">    (otherwise).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">gcv</span><span class="p">()</span><span class="o">.</span><span class="n">set_cutoffs</span><span class="p">(</span><span class="n">nneighb_only</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2008-2016, James Kermode

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>